const app = getApp()
Page({
  data: {
    storeyList: [],
    schoolId: '',
    schoolName: '',
    options: '',
    type: ''
  },
  onLoad: function (options) {
    if (JSON.stringify(options) != '{}') {
      this.setData({
        schoolId: options.schoolId,
        schoolName: decodeURIComponent(options.schoolName),
        type: options.type
      })
      this.getList(this.data.schoolId)
    }
  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  getList(id) {
    app.Http.http({
      url: app.Api.QueryBuildings + '?schoolId=' + id,
      method: 'POST',
      params: {}
    }).then(data => {
      this.setData({ storeyList: data });
    }).catch(err => {
      console.log(err)
    })
  },
  toIndex(e) {
    let id = e.currentTarget.dataset.id;
    let buildingName = e.currentTarget.dataset.buildingname
    if (this.data.type === 'address') {
      app.goBack({ schoolId: this.data.schoolId, buildingId: id, schoolName: decodeURIComponent(this.data.schoolName), buildingName: decodeURIComponent(buildingName) }, 4, 3)
    } else if (this.data.type === 'openShop') {
      app.goBack({ buildingId: id, schoolName: decodeURIComponent(this.data.schoolName), buildingName: decodeURIComponent(buildingName) }, 4, 3)
    } else {
      app.WxService.reLaunch('/pages/index/index', { buildingId: id, schoolName: decodeURIComponent(this.data.schoolName) })
    }

  },
})